using System;
using System.Data;
using System.Collections.Generic;
using System.Text;
using BA.DAL;

namespace BlazeApps.Library.Events
{
    public class EventList : Base
    {
        public enum EventType
        {
            EventsByUser = 0,
            MyEvents = 1
        }

        private BA.DAL.DBUtility DAL = new BA.DAL.DBUtility();
        private Procedures Procs = new Procedures();

        public DataSet GetEvents()
        {
            DAL.CreateDBObjects(ConnectionString, Provider);

            return DAL.GetDataSet(Procs.ListEvents.ToString().Trim(), System.Data.CommandType.Text, System.Data.ConnectionState.Open);
        }

        public DataTable GetEvents(Guid UserID)
        {
            DAL.CreateDBObjects(ConnectionString, Provider);

            DAL.AddParameter("@userid", UserID);

            return DAL.GetDataTable(Procs.ListEventsByUser.ToString().Trim(), System.Data.CommandType.Text, System.Data.ConnectionState.Open);
        }

        public DataTable GetEvents(DateTime Date)
        {
            DAL.CreateDBObjects(ConnectionString, Provider);

            DAL.AddParameter("@date", Date);

            return DAL.GetDataTable(Procs.ListEventsByDate.ToString().Trim(), System.Data.CommandType.Text, System.Data.ConnectionState.Open);
        }

        public DataTable GetEvents(int Month, int Year)
        {
            DAL.CreateDBObjects(ConnectionString, Provider);

            DAL.AddParameter("@month", Month);
            DAL.AddParameter("@year", Year);

            return DAL.GetDataTable(Procs.ListEventsByMonthYear.ToString().Trim(), System.Data.CommandType.Text, System.Data.ConnectionState.Open);
        }

        public DataTable GetEvents(Guid UserID, int Month, int Year, EventType Type)
        {
            DAL.CreateDBObjects(ConnectionString, Provider);
            string Procedure = string.Empty;

            DAL.AddParameter("@userid", UserID);
            DAL.AddParameter("@month", Month);
            DAL.AddParameter("@year", Year);

            if (Type == EventType.EventsByUser)
            {
                Procedure = Procs.ListEventsByUserMonthYear.ToString().Trim();
            }

            if (Type == EventType.MyEvents)
            {
                Procedure = Procs.ListEventsByUserMonthYear.ToString().Trim();
            }

            return DAL.GetDataTable(Procedure, System.Data.CommandType.Text, System.Data.ConnectionState.Open);
        }

        public DataSet GetRecurringEvents(Guid OccurenceID)
        {
            DAL.CreateDBObjects(ConnectionString, Provider);

            DAL.AddParameter("@Occurenceid", OccurenceID);

            return DAL.GetDataSet(Procs.ListEventsByOccurenceID.ToString().Trim(), System.Data.CommandType.Text, System.Data.ConnectionState.Open);
        }
    }
}
